﻿namespace Harness.Commands
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using SHDocVw;

    internal class CloseCommand : ICommand
    {
        #region Constants

        private const int OptionArgIndex = 0;

        #endregion

        #region Public Methods

        public void SyntaxCheck(IHarness harness, IEnumerable<object> args)
        {
            string opt = (args.ElementAtOrDefault(OptionArgIndex) ?? string.Empty).ToString().Trim().ToLower();

            switch (opt)
            {
                case "":
                case "all":
                    break;

                default:
                    string msg = string.Format(Properties.Resources.Exception_UnknownArgument, (OptionArgIndex + 1) + ":" + opt);
                    throw new ArgumentException(msg);
            }
        }

        public dynamic Execute(IHarness harness, IEnumerable<object> args)
        {
            string opt = (args.ElementAtOrDefault(OptionArgIndex) ?? string.Empty).ToString().Trim().ToLower();

            switch (opt)
            {
                case "":
                    IE.Close();
                    break;

                case "all":
                    IE.CloseAll();
                    break;

                default:
                    string msg = string.Format(Properties.Resources.Exception_UnknownArgument, opt);
                    throw new ArgumentException(msg);
            }

            return null;
        }

        #endregion
    }
}
